package com.wy.authority.config;

/**
 * @Author 忘忧
 * @Date Created in 2021/1/14 10:53
 * @Description:
 */
//@Configuration
public class SecurityConfig   {
    //extends WebSecurityConfigurerAdapter
//    @Bean
//    RoleHierarchy roleHierarchy() {
//        RoleHierarchyImpl hierarchy = new RoleHierarchyImpl();
//        hierarchy.setHierarchy("ROLE_admin > ROLE_user");
//        return hierarchy;
//    }
//    @Override
//    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
//      auth.inMemoryAuthentication()
//              .withUser("wy")
//              .password("123456")
//              .roles("admin");
//    }

//    @Override
//    public void configure(WebSecurity web) throws Exception {
//        web.ignoring().antMatchers("/js/**", "/css/**", "/images");
//    }
//
//    @Override
//    protected void configure(HttpSecurity http) throws Exception {
//        http.authorizeRequests()
//                .antMatchers("/*").permitAll();
//                .antMatchers("/roleMange/**").hasRole("ADMIN");
               //.anyRequest().authenticated() ; //其他的需要登陆后才能访问

//                http.formLogin()
//                .loginProcessingUrl("/doLogin");
//                  http.formLogin().defaultSuccessUrl("http://localhost:8080/");   //成功跳转的路径
//                .successHandler((req,resp,authentication) -> {
//                 resp.setContentType("application/json;charset=utf-8");  //authentication.getPrincipal()保存的用户信息
//                    PrintWriter out = resp.getWriter();
//                    out.write(new ObjectMapper().writeValueAsString(authentication.getPrincipal()));
//                    out.flush();
//                    out.close();
        //  })
//                .failureHandler((req,resp,exception) ->{
//                    resp.setContentType("application/json;charset=utf-8");  //authentication.getPrincipal()保存的用户信息
//                    PrintWriter out = resp.getWriter();
//                    out.write(new ObjectMapper().writeValueAsString(exception.getMessage()));
//                    out.flush();
//                    out.close();
//                })
//                .permitAll()
//                .and()
//                .logout()
//                .logoutUrl("/logout")
//                .logoutSuccessHandler((req,resp,authentication) ->{
//                    resp.setContentType("application/json");  //authentication.getPrincipal()保存的用户信息
//                    PrintWriter out = resp.getWriter();
//                    out.write(new ObjectMapper().writeValueAsString("注销成功"));
//                    out.flush();
//                    out.close();
//                })
//                .logoutRequestMatcher(new AntPathRequestMatcher("/logout","POST"))
//                .and()
//                .csrf().disable()
//                .exceptionHandling()
//                .authenticationEntryPoint((req,resp,exception) ->{
//                    PrintWriter out = resp.getWriter();
//                    out.write(new ObjectMapper().writeValueAsString("登录成功"));
//                    out.flush();
//                    out.close();
//                });
//    }
//    }
        }